package cn.moukou.tongji.ihealth.admin.service;

import cn.moukou.tongji.ihealth.admin.dao.DoctorMapper;
import cn.moukou.tongji.ihealth.admin.pojo.Doctor;
import cn.moukou.tongji.ihealth.admin.util.Md5Util;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class DoctorService {

    @Autowired
    DoctorMapper doctorMapper;

    public Doctor getOneDoctor(String id) {
        return doctorMapper.selectById(id);
    }

    public int updateOneDoctor(Doctor doctor) {
        return doctorMapper.updateById(doctor);
    }

    public ArrayList<Doctor> getAllDoctors() {
        return (ArrayList<Doctor>) doctorMapper.selectList(null);
    }

    public int addDoctor(String id, String name, String password, String email, String phoneNumber) {
        Doctor doctor = new Doctor();
        doctor.setId(id);
        doctor.setName(name);
        doctor.setPassword(Md5Util.getMD5String(password));
        doctor.setEmail(email);
        doctor.setPhoneNumber(phoneNumber);
        return doctorMapper.insert(doctor);
    }

}
